﻿using Hotel.BLL;
using Hotel.DAL;
using Hotel.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DisCountController : ControllerBase
    {
        public DisCountController(DisBLL disBLL) 
        {
            DisBLL = disBLL;
        }

        public DisBLL DisBLL { get; }






        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="disCountModel"></param>
        /// <returns></returns>
        [HttpPost]
        public int DisAdd(DisCountModel disCountModel)
        {


            return DisBLL.DisAdd(disCountModel);
        }





       



        ///// <summary>
        ///// 图片上传
        ///// </summary>
        ///// <returns></returns>
        [HttpPost]
        public IActionResult UpFiles(IFormFile file)
        {
            var str = Guid.NewGuid();
            var path = Directory.GetCurrentDirectory() + @"\wwwroot\img" + str + file.FileName;

            using (FileStream fs = new FileStream(path, FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Close();

            }
            return Ok("https://localhost:7276/img" + str + file.FileName);


        }




        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="count"></param>
        /// <param name="page"></param>
        /// <param name="ShopName">门店名称</param>
        /// <param name="Titel">主题</param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DisCountList( string? ShopName="-1", string? Titel="", int index = 1, int size = 3)
        {

            int count = 0; int page = 0;

            var  list= DisBLL.DisCountList(out count, out page, ShopName, Titel, index, size);
            return Ok(new { count = count , page = page , list = list });
        }







        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public int DisCountDel(int id)
        {

            return DisBLL.DisCountDel(id);
        }







        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public DisCountModel DisCountAll(int id)
        {
            return DisBLL.DisCountAll(id);


        }



        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="disCountModel"></param>
        /// <returns></returns>
        [HttpPut]
        public int DisCountUpd(DisCountModel disCountModel)
        {

            return DisBLL.DisCountUpd(disCountModel);


        }














    }
}
